home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / msflex1a / frmflexn.frm next >
Text File  |  1999-09-20  |  6KB  |  207 lines

  1. VERSION 5.00
  2. Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
  3. Begin VB.Form frmFlexNavigate 
  4.    Caption         =   "Ascii Code Table"
  5.    ClientHeight    =   1635
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   3960
  9.    KeyPreview      =   -1  'True
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   1635
  12.    ScaleWidth      =   3960
  13.    StartUpPosition =   2  'CenterScreen
  14.    Begin VB.TextBox tabSimm 
  15.       Height          =   285
  16.       Left            =   120
  17.       TabIndex        =   1
  18.       Text            =   "Text1"
  19.       Top             =   1680
  20.       Width           =   855
  21.    End
  22.    Begin MSFlexGridLib.MSFlexGrid grd 
  23.       Height          =   1455
  24.       Left            =   120
  25.       TabIndex        =   0
  26.       Top             =   120
  27.       Width           =   3735
  28.       _ExtentX        =   6588
  29.       _ExtentY        =   2566
  30.       _Version        =   65541
  31.       FixedCols       =   0
  32.       FocusRect       =   2
  33.    End
  34. End
  35. Attribute VB_Name = "frmFlexNavigate"
  36. Attribute VB_GlobalNameSpace = False
  37. Attribute VB_Creatable = False
  38. Attribute VB_PredeclaredId = True
  39. Attribute VB_Exposed = False
  40. Option Explicit
  41.  
  42. 'Program Documentation:
  43. '
  44. 'Written by: Daniel L. Botkin
  45. 'Date: September 16, 1999
  46. 'Written in: Visual Basic 5.0 (SP3)
  47. '
  48. 'What It Does:
  49. '  Allows user to use the Tab and Shift Tab keys to
  50. '  Navigate between cells in MSFlexGrid.
  51. '
  52. 'Purpose:
  53. '  This code was written to show a very simplictic way
  54. '  of using the tab key for navigation between cells
  55. '  in MSFlexGrid.  It was written to show the basic
  56. '  concept and nothing else.  Please remember that the
  57. '  more code you write to manipulate MSFlexGrid the
  58. '  more this code will have to be modified.
  59. '
  60. 'Why:
  61. '  To this present date I have not been able to find a
  62. '  way to trap the tab key.  Since I use MSFlexGrid in
  63. '  alot of programs I write, I needed a way to navigate
  64. '  between cells in the grid with the Tab key.  This is
  65. '  what I came up with.  If there is a better way, such
  66. '  as through API calls, I would be interested in
  67. '  seeing it.  Since I couldn't beat it I joined it.
  68. '
  69. 'Experianced Programmers:
  70. '  This documentation was written for beginner
  71. '  programmers.  If you are experianced skip the
  72. '  rest and just look at the code, it's not very
  73. '  difficult to figure out.
  74. '
  75. 'Whats Needed:
  76. '  1.  A Form, MSFlexGrid, and Textbox.
  77. '  2.  The Form's KeyPreview property must be set
  78. '      to True.
  79. '  3.  The TabStop properties for all controls except
  80. '      for MSFlexGrid and Textbox should be set
  81. '      to false.
  82. '  4.  The MSFlexGrid TabIndex Property should be set
  83. '      to 0.
  84. '  5.  Navigation code should be put in the
  85. '      Textbox_GotFocus event.
  86. '  6.  The Textbox Visible property must be set to True.
  87. '      If you do not want to see it, place it off the
  88. '      visible portion of the form.
  89. '
  90. 'How It Works:
  91. '  The program will start with focus set to the
  92. '  MSFlexGrid.
  93. '
  94. '  When the tab key is pressed the focus
  95. '  is shifted to the Textbox.  This will in turn invoke
  96. '  the Textbox_GotFocus Event.  The Not ShiftPressed
  97. '  Navigation code is performed and focus is sent
  98. '  back to MSFlexGrid.
  99. '
  100. '  When the Shift is pressed the Form_KeyDown Event is
  101. '  triggered, setting the ShiftPressed flag to true.
  102. '  Then when the Tab is pressed the focus is sent to
  103. '  the Textbox and the Textbox_Gotfocus Event is
  104. '  triggered.  The ShiftPressed code is performed and
  105. '  focus is sent back to MSFlexGrid.
  106. '
  107. '  When the Shift is released the Form_KeyUp Event is
  108. '  triggered, setting the ShiftPressed flag to False.
  109. '  Ready for next set of keys to be pressed.
  110.  
  111. Public ShiftPressed As Boolean
  112.  
  113. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  114.  
  115.     'If the Shift key is pressed, set Public variable
  116.     'ShiftPressed = True.  This flag set to true tells
  117.     'the program the shift key is being pressed.
  118.     
  119.     Select Case Shift
  120.     
  121.     Case 1  'Shift Key
  122.       ShiftPressed = True
  123.     
  124.     Case Else
  125.       'Unload form when Escape is pressed
  126.       'Has nothing to do with navigation, I am just
  127.       'lazy.
  128.       If KeyCode = 27 Then Unload frmFlexNavigate
  129.     
  130.     End Select
  131.     
  132.     
  133. End Sub
  134.  
  135. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
  136.  
  137.     'When the Shift Key is up set the ShiftPressed
  138.     'variable equal to false.
  139.     
  140.     If Shift = 0 Then ShiftPressed = False
  141.     
  142. End Sub
  143.  
  144.  
  145. Private Sub Form_Load()
  146.  
  147.     Dim i As Integer
  148.     
  149.     'Setup MSFlexGrid and assign data.
  150.     With grd
  151.       .Rows = 1
  152.       .FormatString = "^Ascii Code|^Alpha Character"
  153.       .ColWidth(0) = .Width / 2 - 50
  154.       .ColWidth(1) = .Width / 2 - 50
  155.       For i = 65 To 68
  156.         .AddItem i & vbTab & Chr$(i)
  157.       Next i
  158.     End With
  159.     
  160. End Sub
  161.  
  162.  
  163. Private Sub grd_Click()
  164.  
  165. End Sub
  166.  
  167. Private Sub tabSimm_GotFocus()
  168.  
  169.     'This is where you put your desired navigation code
  170.     'for Shift Tab and Tab respectfully.
  171.     
  172.     With grd
  173.       
  174.       'Shift is being pressed.
  175.       If ShiftPressed Then
  176.         If .Col = 1 Then
  177.           .Col = 0
  178.         ElseIf .Row = 1 Then
  179.           .Col = 1
  180.           .Row = .Rows - 1
  181.         Else
  182.           .Col = 1
  183.           .Row = .Row - 1
  184.         End If
  185.       End If
  186.       
  187.       'Shift is not being pressed.
  188.       If Not ShiftPressed Then
  189.         If .Col = 0 Then
  190.           .Col = 1
  191.         ElseIf .Row = .Rows - 1 Then
  192.           .Col = 0
  193.           .Row = 1
  194.         Else
  195.           .Col = 0
  196.           .Row = .Row + 1
  197.         End If
  198.       End If
  199.       
  200.       .SetFocus     'Set focus back to MSFlexGrid
  201.       
  202.     End With
  203.       
  204. End Sub
  205.  
  206.  
  207.